
// #ifndef VUE3
import Vue from 'vue'
import App from './App'
import store from '@/store/store.js'

// 按需导入 $http 对象
import { $http } from '@escook/request-miniprogram'

uni.$http = $http


$http.baseUrl = 'https://api-hmugo-web.itheima.net'

//封装错误提示信息
uni.$showMessage = function(title="数据请求失败"){
	uni.showToast({
		title,
		duration: 1500,
		icon:"error"
	})
}
uni.$showSuccess = function(title="数据加载成功"){
	uni.showToast({
		title,
		duration: 1500,
		icon:"success"
	})
}


// 请求拦截器
$http.beforeRequest = function (options) {
  // do somethimg...
  uni.showLoading({
	  title: '数据加载中....'
  })
  
  //判断请求是否有权限
  // console.log(store)
  // console.log(options)
  if(options.url.indexOf('/my/') != -1){
	  console.log(store.state.m_address.token)
	  options.header = {
		  // 字段的值可以直接从 vuex 中进行获取
		  Authorization: store.state.m_address.token
 	  }
  }
}

// 响应拦截器
$http.afterRequest = function () {
  // do something...
  uni.hideLoading()
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif